package nutz.cyx;


import nutz.cyx.bean.User;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.dao.impl.FileSqlManager;
import org.nutz.dao.impl.NutDao;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;
import org.nutz.resource.Scans;


/**
 * Created by chenyingxi on 2014/5/19.
 */
public class WendalSetup implements Setup {

    private static Log log = Logs.get();

    @Override
    public void init(NutConfig nutConfig) {
        //   log.debug("config ioc"+nutConfig.getIoc());
        NutDao nutDao = nutConfig.getIoc().get(NutDao.class);
        nutDao.setSqlManager(new FileSqlManager("sql/"));
        for (Class<?> klass : Scans.me().scanPackage("nutz.cyx")) {
            if (null != klass.getAnnotation(Table.class)) {
                nutDao.create(klass, false);
            }
        }

        if (nutDao.count(User.class) == 0) {
            User user = new User();
            user.setUsername("admin");
            user.setPassword("123456");
            nutDao.insert(user);
        }

    }

    @Override
    public void destroy(NutConfig nutConfig) {

    }
}
